#include "extendedFilesystemModel.h"

#include <QFileInfo>
#include <QDateTime>

ExtendedFileSystemModel::ExtendedFileSystemModel(QObject *parent) :
    QFileSystemModel(parent),
    countFileOwnerColumn(0),
    countFileCreatedColumn(0)
{
    countFileOwnerColumn = columnCount() - 1;
    countFileCreatedColumn = countFileOwnerColumn - 1;
}

int ExtendedFileSystemModel::columnCount(const QModelIndex &parent) const
{
    this->parent(parent);
    const int newColumnsNumber = 2;
    return QFileSystemModel::columnCount() + newColumnsNumber;
}

QVariant ExtendedFileSystemModel::data(const QModelIndex &index, int role) const
{
    if(!index.isValid()){
        return QFileSystemModel::data(index, role);
    }

    //Set owner column
    if(index.column() == countFileOwnerColumn){
        if(role == Qt::DisplayRole){
            return QString(this->fileInfo(index).owner());
        }
        else if(role == Qt::TextAlignmentRole){
            return Qt::AlignHCenter;
        }
    }//Set time created column
    else if(index.column() == countFileCreatedColumn){
        if(role == Qt::DisplayRole){
            return QString(this->fileInfo(index).created().toString());
        }
        else if(role == Qt::TextAlignmentRole){
            return Qt::AlignHCenter;
        }
    }

    return QFileSystemModel::data(index, role);
}

QVariant ExtendedFileSystemModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if((section == countFileCreatedColumn) && (role == Qt::DisplayRole)) {
        return "Date Created";
    }
    else if((section == countFileOwnerColumn) && (role == Qt::DisplayRole)) {
        return "Owner";
    }
    else {
        return QFileSystemModel::headerData(section,orientation,role);
    }
}

